//
// ICore.hh for Zia in /home/louis-_c//workspace/zia/API
// 
// Made by anthony louis-regis
// Login   <louis-_c@epitech.net>
// 
// Started on  Sun Sep  4 19:08:20 2011 anthony louis-regis
//


#ifndef			__ICORE_HH__
#define			__ICORE_HH__

/**
 *	\file		ICore.hh
 *	\date		Sun Sep  4 2011
 *	\author		LOUIS-REGIS A.
 *	\version	1.0
 */

#include		"Module.hh"
#include		"ILogger.hh"
#include		"HandleRequest.hh"
#include		"HandleResponse.hh"

namespace		Caziac
{

  /**
   *	\class		ICore
   *	\brief		Interface for the caziac api
   */

  class			ICore
  {

  public:
    //Destructor
    virtual ~ICore(){}

    //Member Functions

    /**
     *	\fn		loadModule(const string & modulePath)
     *	\param		modulePath is the path of the module we want to load
     *	\return		bool
     *	\brief		this function load a module dynamically
     */

    virtual bool	loadModule(const std::string & modulePath) = 0;

    /**
     *	\param		moduleName is the of the module we want to unload
     *	\return		bool
     *	\brief		this function unload a modulewich have been previously loaded in memory
     */

    virtual bool	unloadModule(const std::string &moduleName) = 0;

    /**
     *	\param		logger
     *	\brief		this function set a new logger
     */

    virtual void	setLogger(Log::ILogger *logger) = 0;

    /**
     *	\return		logg
     *	\brief		this function set a new logger
     */

    virtual Log::ILog *getLog(Log::Flags const) = 0;

    /**
     *	\brief		this function execute the core
     */

    virtual void	run(Http::HandleRequest &request,
			    Http::HandleResponse &response) = 0;

    /**
     *	\brief		this function stop the core
     */
    
    virtual void	end() = 0;

    static ICore&	getCore();
  };

}

inline std::ostream&		operator << (std::ostream  &os, Caziac::Log::Flags const flag)
{
  std::vector<Caziac::Log::Flags>	vect(7, Caziac::Log::OFF);
  Caziac::Log::ILog *			log;

  vect[0] = Caziac::Log::ERR;
  vect[1] = Caziac::Log::LOG;
  vect[2] = Caziac::Log::WARN;
  vect[3] = Caziac::Log::CONF;
  vect[4] = Caziac::Log::INFO;
  vect[5] = Caziac::Log::FINE;
  vect[6] = Caziac::Log::DEBUG;

  for (unsigned int i = 0; i < vect.size(); ++i)
    {
      log = NULL;
      if (vect[i] & flag)
	log = Caziac::ICore::getCore().getLog(vect[i]);
      if (log != NULL)
	*log << os;
    }
  return os;
}

#endif
